<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>/net/nas/exports/srv/www/webapps/Projects/Java/CS222/Seminar_2/AssignmentTwo/src/PartB.java.html</title>
<meta name="Generator" content="Vim/7.1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000"><font face="monospace">
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;PartB.java</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;1.</font><font color="#0000ff">&nbsp;Create a dog class. Specify size, breed, and name of dog (variables).</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Add a method bark to class dog that will print out “Ruff! Ruff!”</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Creater a tester class that instantiates an object d for class dog. </font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Set the size of d to 40.</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Call the method bark()</font><br>
<font color="#0000ff">&nbsp;* </font><br>
<font color="#0000ff">&nbsp;* 2. Next make the variables private. Try to compile and run the program</font><br>
<font color="#0000ff">&nbsp;* </font><br>
<font color="#0000ff">&nbsp;* 3. Add get and set method to access the private variables.</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Submit all programs using the file attachment provided.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* </font><font color="#6a5acd">@author</font><font color="#0000ff">: John Thomason</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Date: Nov 13, 2008 / 7:25:24 AM</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp; Class: CIS252 - Introduction to Java Programming</font><br>
<font color="#0000ff">&nbsp;*/</font><br>
<br>
<br>
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Driver class for Dog class testing</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;PartB Class</font><br>
<font color="#6a5acd">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;PartB {<br>
<br>
&nbsp;&nbsp;<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Application Entry Point</font><br>
<font color="#0000ff">&nbsp;&nbsp; </font><font color="#0000ff">* </font><font color="#6a5acd">@param</font><font color="#008b8b">&nbsp;args</font><font color="#0000ff">&nbsp;The command line arguments</font><br>
<font color="#0000ff">&nbsp;&nbsp; */</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>static</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;main(String[]&nbsp;args)&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">//New Dog</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;Dog d = <font color="#a52a2a"><b>new</b></font>&nbsp;Dog(<font color="#ff00ff">40</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">//Required bark() call</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;d.bark();<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">//A little extra</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;prt(d.toString());<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">//New Dog</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;Dog d2 = <font color="#a52a2a"><b>new</b></font>&nbsp;Dog(<font color="#ff00ff">10</font>, <font color="#ff00ff">&quot;Fifi&quot;</font>, <font color="#ff00ff">&quot;Poodle&quot;</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;d2.setBarkTone(<font color="#ff00ff">&quot;Le'Bark! Le'Bark!&quot;</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;prt(d2.toString());<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;}<font color="#0000ff">//end main()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Display a formatted message string</font><br>
<font color="#0000ff">&nbsp;&nbsp; </font><font color="#0000ff">* </font><font color="#6a5acd">@param</font><font color="#008b8b">&nbsp;msg</font><font color="#0000ff">&nbsp;The formatted message string</font><br>
<font color="#0000ff">&nbsp;&nbsp; */</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>protected</b></font>&nbsp;<font color="#2e8b57"><b>static</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;prt(String msg){<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(msg);<br>
&nbsp;&nbsp;}<font color="#0000ff">//prt()</font><br>
<br>
}<font color="#0000ff">//end PartB class</font><br>
<br>
<br>
<font color="#2e8b57"><b>class</b></font>&nbsp;Dog {<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#0000ff">//Instance Variables</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;Integer size;<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;String&nbsp;&nbsp;breed, name;<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;String&nbsp;&nbsp;barkTone = <font color="#ff00ff">&quot;Ruff! Ruff!&quot;</font>;<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#0000ff">//Constructors</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;Dog(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>(<font color="#ff00ff">25</font>);<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;Dog(Integer size){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>(size, <font color="#ff00ff">&quot;Dog&quot;</font>);<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;Dog(Integer size, String name){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>(size, name, <font color="#ff00ff">&quot;Mutt&quot;</font>);<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;Dog(Integer size, String name, String breed){<br>
&nbsp;&nbsp;&nbsp;&nbsp;setSize(size);<br>
&nbsp;&nbsp;&nbsp;&nbsp;setName(name);<br>
&nbsp;&nbsp;&nbsp;&nbsp;setBreed(breed);<br>
&nbsp;&nbsp;}<font color="#0000ff">//Dog()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#0000ff">//Accessors</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;Integer getSize(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;size;<br>
&nbsp;&nbsp;}<font color="#0000ff">//getSize()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;String getName(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;name; <br>
&nbsp;&nbsp;}<font color="#0000ff">//getName()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;String getBreed(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;breed;<br>
&nbsp;&nbsp;}<font color="#0000ff">//getBreed()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;String getBarkTone(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;barkTone;<br>
&nbsp;&nbsp;}<font color="#0000ff">//barkTone()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#0000ff">//Mutators</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;setSize(Integer size){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>.size = size;<br>
&nbsp;&nbsp;}<font color="#0000ff">//setSize()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;setName(String name){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>.name = name;<br>
&nbsp;&nbsp;}<font color="#0000ff">//setName()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;setBreed(String breed){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>.breed = breed;<br>
&nbsp;&nbsp;}<font color="#0000ff">//setBreed()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;setBarkTone(String barkTone){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>.barkTone = barkTone;<br>
&nbsp;&nbsp;}<font color="#0000ff">//setBarkTone()</font><br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#0000ff">//Other public methods</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;bark(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;bark(getBarkTone());<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;bark(String barkTone){<br>
&nbsp;&nbsp;&nbsp;&nbsp;PartB.prt(barkTone + <font color="#ff00ff">&quot;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>);<br>
&nbsp;&nbsp;}<font color="#0000ff">//bark()</font><br>
<br>
&nbsp;&nbsp;<font color="#a020f0">@Override</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;String toString(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;String.format(<font color="#ff00ff">&quot;</font><font color="#6a5acd">\n</font><font color="#ff00ff">%s (That's Hi! in %s lingo)</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>&nbsp;+<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#ff00ff">&quot;My name is </font><font color="#6a5acd">\&quot;</font><font color="#ff00ff">%s</font><font color="#6a5acd">\&quot;</font><font color="#ff00ff">, &quot;</font>&nbsp;+<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#ff00ff">&quot;and I weigh %s pounds.</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">&quot;</font>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getBarkTone(),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getBreed(),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getName(),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getSize());<br>
&nbsp;&nbsp;}<font color="#0000ff">//toString()</font><br>
&nbsp;&nbsp;<br>
}<font color="#0000ff">//Dog class</font><br>
<br>
<br>
</font></body>
</html>
